package hz.mobileproject.pda.ui.activity.work;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import cn.droidlover.xdroidmvp.mvp.XActivity;
import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.ImpBuWeiBean;
import hz.mobileproject.pda.entity.request.Request_Imp_List;
import hz.mobileproject.pda.presenter.PNoneImpBuWei;
import hz.mobileproject.pda.ui.adapter.ImpBuWeiAdapter;

public class NoneImpBuWeiActivity extends XActivity<PNoneImpBuWei> {

    private RecyclerView recyclerView_noneImp;
    private Gson gson;
    private SPUtils mSPUtils;

    private String departmentId_imp;
    private String check_id_imp;
    private String cusnumber;
    private List<ImpBuWeiBean> impBuWeiBeanList;
    private ImpBuWeiAdapter mImpBuWeiAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onWidgetClick(View view) {

    }

    @Override
    public void initData(Bundle savedInstanceState) {
        recyclerView_noneImp = (RecyclerView) findViewById(R.id.recyclerView_noneImp);
        recyclerView_noneImp.setLayoutManager(new LinearLayoutManager(NoneImpBuWeiActivity.this));
        gson = new Gson();
        mSPUtils = SPUtils.getInstance("app_login");
        departmentId_imp = mSPUtils.getString("departmentId_imp");
        check_id_imp = mSPUtils.getString("check_id_imp");
        cusnumber = mSPUtils.getString("cusNumber_imp");
        //cusNumber_imp

        Request_Imp_List request_imp_list = new Request_Imp_List(cusnumber,departmentId_imp,check_id_imp);
        String requestJson = gson.toJson(request_imp_list);
        getP().setData(requestJson,1);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_none_imp_bu_wei;
    }

    @Override
    public PNoneImpBuWei newP() {
        return new PNoneImpBuWei();
    }


    public void setView(String data_json, int type) {
        switch (type) {
            case 1: {
                impBuWeiBeanList = gson.fromJson(data_json,new TypeToken<List<ImpBuWeiBean>>(){}.getType());
                if(impBuWeiBeanList == null) {
                    ToastUtils.showLong("网络失败,无法查看未巡查重点部位");
                    return;
                }
                mImpBuWeiAdapter = new ImpBuWeiAdapter(impBuWeiBeanList);
                recyclerView_noneImp.setAdapter(mImpBuWeiAdapter);
            }
            break;
        }
    }
}
